package com.serverlessdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;
import java.util.stream.Collectors;

@SpringBootApplication
@Controller
public class ServerlessDemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(ServerlessDemoApplication.class, args);
  }

  @RequestMapping("/nums/calc")
  @ResponseBody
  Object helloWorld() {
    Map<String, Object> map = new LinkedHashMap<>();
    List<Double> nums = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
      double value = new Random().nextDouble();
      nums.add(value);
    }
    map.put("generateNums", nums);
    map.put("sumValue", nums.stream().collect(Collectors.summarizingDouble(t -> t)).getSum());
    return map;
  }
}
